function getURLParams(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
	var r = window.location.search.substr(1).match(reg);
	if (r != null) {
		return unescape(r[2]);
	}
	return null; 
}

function findCountrys(){
	 $("#destlist").empty();
	 $("#holylist").empty();
	 $.ajax({
		 type: 'POST',
		 url: '/diving-back/product/cityJson.do',
		 success: function(msg){			 
			if(msg!=""||msg!=null){
				 for(var i=0;i<msg.length;i++){
					 $('#citylist').append("<option value='"+msg[i].country_ID+"'>"+msg[i].country_Name+"</option>");
				 }
			 }
		 }
	 });
}

//查找目的地信息 
function findDesitinations(){
	$("#holylist").empty();
	var options=$("#citylist option:selected");
	var countryID=options.val();
	$.ajax({
		type: 'POST',
		url: '/diving-back/product/destJson.do',
		data: {countryID:countryID},
		success: function(msg){
			if(msg!=""||msg!=null){
				for(var i=0;i<msg.length;i++){
					$('#destlist').append("<option value='"+msg[i].dest_ID+"'>"+msg[i].dest_Name+"</option>");
				}
			}
		}
	});
}

//查找圣地信息
function findHolylands(){
	var options=$("#citylist option:selected");
	var options1=$("#destlist option:selected");
	var countryID=options.val();
	var destId=options1.val();
	 $.ajax({
		 type: 'POST',
		 url: '/diving-back/product/holylandJson.do',
		 data: {countryID : countryID,destId : destId},
		 success: function(msg){
			 if(msg!=""||msg!=null){
				 for(var i=0;i<msg.length;i++){
					 $('#holylist').append("<option value='"+msg[i].holyland_ID+"'>"+msg[i].holyland_Name+"</option>");
				 }
			 }
		 }
	 });
}
//上传图片
function initUploadCtrl(flag) {
	var options =
	{
		thumbBox: '.thumbBox' + flag,
		spinner: '.spinner' + flag,
		imgSrc: '',
	};
	var cropper = $('.imageBox' + flag).cropbox(options);
	
	$('#file' + flag).on('change', function(){
		var reader = new FileReader();
		reader.onload = function(e) {
			options.imgSrc = e.target.result;
			cropper = $('.imageBox' + flag).cropbox(options);
		};
		reader.readAsDataURL(this.files[0]);
		this.files = [];
	});
	$('#btnCrop' + flag).on('click', function(){
		var img = cropper.getDataURL();
			var picsval = $('#pictures').val();
			if(picsval != '') {
				picsval = picsval.substring(0,picsval.length - 1);
			}
			var pics = picsval.split(',');
			if(pics.length >= 5) {
				alert('最多能上传5张图片');
				return;
			}
		$.ajax({
			type: 'POST',
			url: '/diving-back/api/file/uploadByBase64NotSaveDB.do',
			data: {base64 : img},
			success: function(msg){
				if(msg.code != 200) {
					alert(msg.message);
				}else{
					//alert(msg.path);
					$('#pictures').val(msg.path + ',' + $('#pictures').val());
				}
			}
		});
	$('.cropped' + flag).append('<img src="'+img+'" width="200" height="100">');
	});
	$('#btnZoomIn' + flag).on('click', function(){
		cropper.zoomIn();
	});
	$('#btnZoomOut' + flag).on('click', function(){
		cropper.zoomOut();
	});
}